package com.some.jobdescapp.model;

import android.graphics.Color;
import android.support.annotation.NonNull;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.randy.recyclerviews.adapter.ExpandableList;
import com.randy.recyclerviews.adapter.UniversalAdapter;
import com.some.jobdescapp.R;
import com.some.jobdescapp.bean.GroupEntity;

/**
 * @author RANDY.ZHANG
 * @version 1.0
 * @company:
 * @date 2019/1/8 22:21
 */
public class TitleModel extends UniversalAdapter.AbstractModel<TitleModel.ViewHolder>{

    private GroupEntity groupEntity;
    private ExpandableList expandableList;

    @Override
    public int getLayoutRes() {
        return R.layout.adapter_expandable_header;
    }

    @NonNull
    @Override
    public UniversalAdapter.IViewHolderCreator<ViewHolder> getViewHolderCreator() {
        return new UniversalAdapter.IViewHolderCreator<ViewHolder>() {
            @NonNull
            @Override
            public ViewHolder create(@NonNull View view) {
                return new ViewHolder(view);
            }
        };
    }

    @Override
    public void bindData(@NonNull ViewHolder holder) {
        super.bindData(holder);
        holder.titleTextView.setText(groupEntity.getTitle());
        if (groupEntity.isCollapsed()) {
            holder.arrowView.setRotation(0);
            holder.itemView.setBackgroundColor(Color.WHITE);
        } else {
            holder.arrowView.setRotation(90);
            holder.itemView.setBackgroundColor(Color.parseColor("#EEEEEE"));
        }
    }

    public void setGroupEntity(GroupEntity groupEntity) {
        this.groupEntity = groupEntity;
    }

    public GroupEntity getGroupEntity() {
        return groupEntity;
    }

    public void setExpandableList(ExpandableList expandableList) {
        this.expandableList = expandableList;
    }

    public ExpandableList getExpandableList() {
        return expandableList;
    }

    public class ViewHolder extends UniversalAdapter.ViewHolder {
        private ImageView arrowView;
        private TextView titleTextView;
        public ViewHolder(View itemView) {
            super(itemView);
            arrowView = itemView.findViewById(R.id.iv_arrow);
            titleTextView = itemView.findViewById(R.id.tv_header);
        }
    }
}
